package com.google.gwt.user.client.ui;

import com.google.gwt.user.client.ui.*;
import org.liujing.jsw.client.ui.plaf.*;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.*;
import java.util.*;
import org.liujing.jsw.client.ui.*;
import org.liujing.jsw.client.border.Border;

public class WidgetWrapper extends Widget implements JComponent{
	
	protected ComponentImpl impl;
	protected Widget targetWidget;
	
	public WidgetWrapper(Widget w){
		impl = new ComponentImpl(this);
		updateUI();
		targetWidget = w;
		impl.setDomElement(targetWidget.getElement());
		setMinimumSize(new Dimension(1, 1));
	}
	
	@Override
	public com.google.gwt.user.client.Element getElement(){
		return targetWidget.getElement();
	}
	
	public void setChildElementOffset(int x, int y){
		impl.setChildElementOffset(x, y);
	}
	
	public int getChildElementOffsetX(){
		return impl.getChildElementOffsetX();
	}
	
	public int getChildElementOffsetY(){
		return impl.getChildElementOffsetY();
	}
	
	public void updateUI() {
		impl.setUI(UIManager.getUI(this));
	}
	
	public void setUI(ComponentUI newUI) {
        impl.setUI(newUI);
    }
    
	public void onResize(){
	}
	
	public void onAttach(){
		//if(impl.isDomElementSet())
		targetWidget.onAttach();
		impl.onAttach();
	}
	
	public void onDetach(){
		//if(isDomElementSet())
			targetWidget.onDetach();
		impl.onDetach();
	}
	public void addNotify() {
		impl.addNotify();
	}
	
	public void setDomElement(com.google.gwt.user.client.Element elem) {
		impl.setDomElement(elem);
		targetWidget.setElement(elem);
	}
	
	public Element getDomElement(){
		return targetWidget.getElement();
	}
	
	
	public boolean isDomElementSet(){
		return impl.isDomElementSet();
	}
	
	public void setContentElement(com.google.gwt.dom.client.Element elem) {
		impl.setContentElement(elem);
	}
	
	public Element getContentElement(){
		return impl.getContentElement();
	}
	
	public void removeNotify() {
		impl.removeNotify();
	}
	
	public void setBorder(Border border){
		impl.setBorder(border);
	}
	
	public Border getBorder(){
		return impl.getBorder();
	}
	
	public void setParent(Container c){
		impl.setParent(c);
	}
	
	public Container getParent(){
		return impl.getParent();
	}
	
	public void invalidate() {
		impl.invalidate();
    }
    
    public void setPreferredSize(Dimension preferredSize) {
       impl.setPreferredSize(preferredSize);
    }


    /**
     * Returns true if the preferred size has been set to a
     * non-<code>null</code> value otherwise returns false.
     *
     * @return true if <code>setPreferredSize</code> has been invoked
     *         with a non-null value.
     * @since 1.5
     */ 
    public boolean isPreferredSizeSet() { 
        return impl.isPreferredSizeSet();
    }


    /**
     * Gets the preferred size of this component.
     * @return a dimension object indicating this component's preferred size
     * @see #getMinimumSize
     * @see LayoutManager
     */
    public Dimension getPreferredSize() {
    	return impl.getPreferredSize();
    }
    
    public void setMinimumSize(Dimension minimumSize) {
        impl.setMinimumSize(minimumSize);
    }

    public boolean isMinimumSizeSet() {
        return impl.isMinimumSizeSet();
    }

    public Dimension getMinimumSize() {
    	return impl.getMinimumSize();
    }

    public void setMaximumSize(Dimension maximumSize) {
        impl.setMaximumSize(maximumSize);
    }
 
    public boolean isMaximumSizeSet() { 
        return impl.isMaximumSizeSet();
    }

    public Dimension getMaximumSize(){
        return impl.getMaximumSize();
    }
    
    public Dimension getSize() {
        return impl.getSize();
    }
    
    public void setSize(int width, int height) {
        impl.setSize(width, height);
    }

    @Deprecated
    public void resize(int width, int height) {            
            impl.resize(width, height);
    }
    
    public void setBounds(int x, int y, int width, int height) {
        impl.setBounds(x, y, width, height);
    }
    

    public void setSize(Dimension d) {
        impl.setSize(d);
    }
    
    public float getAlignmentX() {
        return impl.getAlignmentX();
    }

    public float getAlignmentY() {
    	return impl.getAlignmentY();
    }
    
    public void setAlignmentY(float alignmentY) {
        impl.setAlignmentY(alignmentY);
    }
    
    public void setAlignmentX(float alignmentX) {
        impl.setAlignmentX(alignmentX);
    }
    
    public boolean isValid() {
        return impl.isValid();
    }
    
    public ComponentOrientation getComponentOrientation() {
        return impl.getComponentOrientation();
    }
    

    
    public Insets getInsets() {
        return impl.getInsets();
    }
    
    public boolean contains(int x, int y) {
        return impl.contains(x, y);
    }
    
    @Deprecated
    public boolean inside(int x, int y) {
        return impl.inside(x, y);
    }
    
    public void revalidate() {
    	impl.revalidate();
    }
    
    public boolean isVisible() {
    	return targetWidget.isVisible();
    }
}
